package Collection;
import java.util.Arrays;
import java.util.List;

public class ArrayToList {
    public static void main(String[] args) {
        String[] strings = {"one","two","three","four","five"};
        System.out.println("strings"+ Arrays.toString(strings));
        //asList()方法会返回内部的ArrayList，内部直接返回数组的引用
        List<String> list = Arrays.asList(strings);
        System.out.println("list"+list);
        //数组发生改变，集合也会发生改变
        strings[1] = "six";
        System.out.println("strings"+ Arrays.toString(strings));
        System.out.println("list"+list);
        //集合发生改变，数组也会改变
        list.set(2,"seven");
        System.out.println("strings"+ Arrays.toString(strings));
        System.out.println("list"+list);

        //给集合添加/删除元素相当于给数组添加/删除元素
        //而数组是定长的，不会自动扩容/缩容，因此发生不支持操作异常
//        list.add("!!!");
    }
}
